﻿Imports System.Data.SqlClient
Public Class clsVEHICULO
    Private mstrID_VEHICULO As String
    Private mstrCOD_VEHICULO As String
    Private mstrNUMERO_ESCLAVO As String
    Private mstrID_SECTOR As String
    Private mstrIP_CLIENTE As String
    Public Property ID_VEHICULO() As String
        Get
            Return mstrID_VEHICULO
        End Get
        Set(ByVal value As String)
            mstrID_VEHICULO = value
        End Set
    End Property
    Public Property COD_VEHICULO() As String
        Get
            Return mstrCOD_VEHICULO
        End Get
        Set(ByVal value As String)
            mstrCOD_VEHICULO = value
        End Set
    End Property
    Public Property NUMERO_ESCLAVO() As String
        Get
            Return mstrNUMERO_ESCLAVO
        End Get
        Set(ByVal value As String)
            mstrNUMERO_ESCLAVO = value
        End Set
    End Property
    Public Property ID_SECTOR() As String
        Get
            Return mstrID_SECTOR
        End Get
        Set(ByVal value As String)
            mstrID_SECTOR = value
        End Set
    End Property
    Public Property IP_CLIENTE() As String
        Get
            Return mstrIP_CLIENTE
        End Get
        Set(ByVal value As String)
            mstrIP_CLIENTE = value
        End Set
    End Property
    Public Sub New()
        mstrID_VEHICULO = ""
        mstrCOD_VEHICULO = ""
        mstrNUMERO_ESCLAVO = ""
        mstrID_SECTOR = ""
        mstrIP_CLIENTE = ""
    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into VEHICULO (" & _
                            "ID_VEHICULO," & _
                            "COD_VEHICULO," & _
                            "NUMERO_ESCLAVO," & _
                            "ID_SECTOR," & _
                            "IP_CLIENTE)" & _
                            "VALUES (" & _
                            "SUBSTRING(@ID_VEHICULO,1,100)," & _
                            "SUBSTRING(@COD_VEHICULO,1,100)," & _
                            "SUBSTRING(@NUMERO_ESCLAVO,1,100)," & _
                            "SUBSTRING(@ID_SECTOR,1,100)," & _
                            "SUBSTRING(@IP_CLIENTE,1,100))"

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = OptocontrolConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("ID_VEHICULO", mstrID_VEHICULO)
        Command.Parameters.AddWithValue("COD_VEHICULO", mstrCOD_VEHICULO)
        Command.Parameters.AddWithValue("NUMERO_ESCLAVO", mstrNUMERO_ESCLAVO)
        Command.Parameters.AddWithValue("ID_SECTOR", mstrID_SECTOR)
        Command.Parameters.AddWithValue("IP_CLIENTE", mstrIP_CLIENTE)

        cnConn.Open()
        Dim RowsAffected As Integer
        Try
            RowsAffected = Command.ExecuteNonQuery
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Aviso")
        End Try

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar el registro de vehiculo", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
    Public Sub Actualizar()

        Dim strSqlQry As String
        Dim cnConn As New SqlConnection

        cnConn.ConnectionString = OptocontrolConnection
        strSqlQry = "Update VEHICULO Set " & _
                    "COD_VEHICULO=SUBSTRING(@COD_VEHICULO,1,100)," & _
                    "NUMERO_ESCLAVO=SUBSTRING(@NUMERO_ESCLAVO,1,100)," & _
                    "ID_SECTOR=SUBSTRING(@ID_SECTOR,1,100)," & _
                    "IP_CLIENTE=SUBSTRING(@IP_CLIENTE,1,100) " & _
                    "Where ID_VEHICULO=@ID_VEHICULO"


        Dim Command As New SqlCommand(strSqlQry, cnConn)

        Command.Parameters.AddWithValue("ID_VEHICULO", mstrID_VEHICULO)
        Command.Parameters.AddWithValue("COD_VEHICULO", mstrCOD_VEHICULO)
        Command.Parameters.AddWithValue("NUMERO_ESCLAVO", mstrNUMERO_ESCLAVO)
        Command.Parameters.AddWithValue("ID_SECTOR", mstrID_SECTOR)
        Command.Parameters.AddWithValue("IP_CLIENTE", mstrIP_CLIENTE)
        cnConn.Open()

        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible actualizar el conductor ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If





    End Sub
End Class
